package iie.tools;

//package cn.ac.iie.di.ban.nmpp.tools;
//
//import com.trs.ckm.batch.BatchResource;
//import com.trs.ckm.batch.BatchText;
//import com.trs.ckm.batch.DefinedResult;
//import com.trs.ckm.batch.FilesBatchResult;
//import com.trs.ckm.batch.InterFaceBatchResult;
//import com.trs.ckm.batch.SingleBatchResult;
//import com.trs.ckm.batch.SourceBatchResult;
//import com.trs.ckm.soap.CkmSoapException;
//import com.trs.ckm.soap.TrsCkmSoapClient;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import org.apache.log4j.Logger;
//
//public class TRSPtools {
//
//    private String trsUrls = null;
//    private TrsCkmSoapClient client;
//    private static Logger logger = Logger.getLogger(TRStools3.class.getName());
//
//    public TRSPtools() {
//        this.trsUrls = RuntimeEnv.Trskhd2[0];
////    trsUrls = "http://10.136.65.34:8000;http://10.136.65.35:8000;http://10.136.65.36:8000;http://10.136.65.38:8000;http://10.136.65.37:8000;http://10.136.65.38:8000;http://10.136.65.39:8000;http://10.136.65.40:8000;http://10.136.65.41:8000;http://10.136.65.42:8000;http://10.136.65.43:8000;http://10.136.65.44:8000;http://10.136.65.45:8000;http://10.136.65.46:8000;http://10.136.65.47:8000;http://10.136.65.48:8000;http://10.136.65.49:8000;http://10.136.65.50:8000;http://10.136.65.51:8000";
//    }
//
//    public Map<Integer, String[]> getMCatagoryIndustry(List<String> contAll) {
//        Long startTime = System.currentTimeMillis();
//        while (true) {
//            if (this.client == null) {
//                init();
//            }
//            try {
//                Integer times = 0;
//                Map<Integer, String[]> trsResult = new HashMap<>();
//                List<String> conts = new ArrayList<>();
//                int countConts = contAll.size();
//                for (int k = 0; k < contAll.size(); k += 20) {
//                    if (contAll.size() - k < 20) {
//                        conts = contAll.subList(k, contAll.size());
//                    } else {
//                        conts = contAll.subList(k, k + 20);//
//                    }
//                    trsResult.putAll(testCkmInterfaceBatchRuleCAT(client, conts, times));
//                    times++;
//                }
//                if (trsResult.size() != countConts) {
//                    throw new RuntimeException("trs error data size error!");
//                }
//                Long endTime = System.currentTimeMillis();
//                logger.info("conts: " + contAll.size() + " trsResult: " + trsResult.size() + " trsTime use " + (endTime - startTime) + " ms");
//                return trsResult;
//            } catch (CkmSoapException ex) {
//                logger.error("trserror  and continue" + ex);
//                String errorStr = ex.toString();
//                if (errorStr.contains("http")) {
//                    String urlD = errorStr.substring(errorStr.indexOf("http"), errorStr.indexOf("8000") + 4);
//                    this.trsUrls = getTrsUrl(this.trsUrls, urlD);
//                }
//                this.client = null;
//            } catch (Exception e) {
//                logger.error("trserror  and continue" + e);
//                String errorStr = e.toString();
//                if (errorStr.contains("http")) {
//                    String urlD = errorStr.substring(errorStr.indexOf("http"), errorStr.indexOf("8000") + 4);
//                    this.trsUrls = getTrsUrl(this.trsUrls, urlD);
//                }
//                this.client = null;
//            }
//        }
//    }
//
//    private void init() {
//        this.client = new TrsCkmSoapClient();
//        String[] trs = RuntimeEnv.Trskhd2;
////    String[] trs = "http://10.136.65.34:8000;http://10.136.65.35:8000;http://10.136.65.36:8000;http://10.136.65.38:8000;http://10.136.65.37:8000;http://10.136.65.38:8000;http://10.136.65.39:8000;http://10.136.65.40:8000;http://10.136.65.41:8000;http://10.136.65.42:8000;http://10.136.65.43:8000;http://10.136.65.44:8000;http://10.136.65.45:8000;http://10.136.65.46:8000;http://10.136.65.47:8000;http://10.136.65.48:8000;http://10.136.65.49:8000;http://10.136.65.50:8000;http://10.136.65.51:8000|admin|trsadmin".split("[|]");
//        logger.info("can use trsurl :" + this.trsUrls);
//        this.client.SetServer(this.trsUrls, trs[1], trs[2]);
//    }
//
//    /**
//     * 得到可用的trsUrl 如果不可用就移除 如果集合中的url少于10那么就从新赋值配置信息
//     *
//     * @param urlString
//     * @param urlD
//     * @return
//     */
//    public String getTrsUrl(String urlString, String urlD) {
//        List urlList = new ArrayList();
//        String[] urlStrings = urlString.split(";");
//        for (String url : urlStrings) {
//            urlList.add(url);
//        }
//        if (urlList.size() < 10) {
//            this.trsUrls = getTrsUrl(RuntimeEnv.Trskhd2[0], null);
//            return this.trsUrls;
//        }
//        urlList.remove(urlD);
//        String urlLists = urlList.toString().replaceAll(", ", ";");
//        urlLists = urlLists.substring(1, urlLists.length() - 1);
//        return urlLists;
//    }
//
//    /////////////////////////////////////////////////
//    //规则分类
//    /////////////////////////////////////////////////
//    /*
//  批量trs
//     */
//    private Map<Integer, String[]> testCkmInterfaceBatchRuleCAT(TrsCkmSoapClient _client, List<String> conts, Integer times) throws CkmSoapException {
//        Map<Integer, String[]> trsResult = new HashMap();
//        String _sInterfaceName = "Trs__RuleCATClassifyText";
//        BatchResource[] _resources = new BatchResource[1];
//        _resources[0] = new BatchResource("内容行业分类");
//        BatchText[] _texts = new BatchText[conts.size()];
////        _texts[0] = new BatchText("Windows平台在windows命令行窗口下执行查看所有的端口占用情况", "0");
//        for (int i = 0; i < conts.size(); i++) {
//            _texts[i] = new BatchText(conts.get(i), "0");
//        }
////        _texts[0] = new BatchText("国家食品药品监督管理总局药品医疗器械", "0");
////        _texts[1] = new BatchText("国家食品药品监督管理总局药品医疗器械", "0");
//        InterFaceBatchResult _retValue = _client.CkmInterfaceBatch(_sInterfaceName, _resources, _texts, null);
//        if (_retValue != null) {
//            FilesBatchResult[] _filesBatchResults = _retValue.getWordlist();
////            System.out.println("FilesBatchResult len:" + _filesBatchResults);
//
//            if (_filesBatchResults != null) {
//                for (int i = 0; i < _filesBatchResults.length; i++) {
//                    SourceBatchResult[] _sourceBatchResults = _filesBatchResults[i].getWordlist();
////                    System.out.println("SourceBatchResult:" + _sourceBatchResults);//为null
//                    String[] a = {};
//                    trsResult.put(i + times * 20, a);
//                    if (_sourceBatchResults != null) {
//                        for (int j = 0; j < _sourceBatchResults.length; j++) {
//                            SingleBatchResult[] _singleBatchResults = _sourceBatchResults[j].getWordlist();
////                            System.out.println("SingleBatchResult:" + _singleBatchResults);
//
//                            if (_singleBatchResults != null) {
//                                for (int k = 0; k < _singleBatchResults.length; k++) {
//                                    if (_singleBatchResults[k] != null) {
//                                        DefinedResult[] _definedResults = _singleBatchResults[k].getWordlist();
////                                        System.out.println("DefinedResult:" + _definedResults);
//                                        for (int m = 0; m < _definedResults.length; m++) {
//                                            if (_definedResults[m] != null) {
////                                                System.out.print("i、" + i + ",j、" + j + ",k、" + k + ",m、" + m + ":");
////                                                System.out.println(_definedResults[m].getStr());
//                                                trsResult.put(i + times * 20, _definedResults[m].getStr().split(";"));
//                                            } else {
////                                                System.out.print("i、" + i + ",j、" + j + ",k、" + k + ",m、" + m + ":");
////                                                System.out.println("null.");
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//        }
//        return trsResult;
//    }
//
//    /////////////////////////////////////
////        public static void main(String[] args) throws CkmSoapException {
////        TRSPtools trsp = new TRSPtools();
////        TrsCkmSoapClient client = new TrsCkmSoapClient();
////**
//// * http://10.136.65.34:8000;http://10.136.65.35:8000;http://10.136.65.36:8000;http://10.136.65.38:8000;http://10.136.65.37:8000;http://10.136.65.38:8000;http://10.136.65.39:8000;http://10.136.65.40:8000;http://10.136.65.41:8000;http://10.136.65.42:8000;http://10.136.65.43:8000;http://10.136.65.44:8000;http://10.136.65.45:8000;http://10.136.65.46:8000;http://10.136.65.47:8000;http://10.136.65.48:8000;http://10.136.65.49:8000;http://10.136.65.50:8000;http://10.136.65.51:8000|admin|trsadmin
//// */
////        client.SetServer("http://10.136.65.34:8000;http://10.136.65.35:8000;http://10.136.65.36:8000;http://10.136.65.38:8000;http://10.136.65.37:8000;http://10.136.65.38:8000;http://10.136.65.39:8000;http://10.136.65.40:8000;http://10.136.65.41:8000;http://10.136.65.42:8000;http://10.136.65.43:8000;http://10.136.65.44:8000;http://10.136.65.45:8000;http://10.136.65.46:8000;http://10.136.65.47:8000;http://10.136.65.48:8000;http://10.136.65.49:8000;http://10.136.65.50:8000;http://10.136.65.51:8000", "admin", "trsadmin");
////
////        System.out.println("===================规则分类=====================");
////        List<String> conts = new ArrayList<>();
////        conts.add("Windows平台在windows命令行窗口下执行查看所有的端口占用情况");
////        conts.add("国家食品药品监督管理总局药品医疗器械");
////        conts.add("消防电子的国标又改变了");
////        conts.add("国家食品药品监督管理总局药品医疗器械");
////        conts.add("药品");
////        conts.add("医疗器械");
////        conts.add("制造业");
////        conts.add("");
////        conts.add("国家食品药品监督管理总局");
////        for(int i=0;i<1500;i++){
////            String trs = "国家食品药品监督管理总局药我是一个冰。来数字是你奥房贷首付斯蒂芬阿飞聚少离多方法是品医疗器械";
////            conts.add(trs);
////        }
////        Map<Integer,String[]> trsResult = trsp.testCkmInterfaceBatchRuleCAT(client, conts);
////        Set<Integer> ket = trsResult.keySet();
////        for(Integer i : ket){
////            System.out.println(i+" "+Arrays.toString(trsResult.get(i)));
////        }
////        System.out.print(trsResult.toString());
//    /* String[] sss = getMCatagoryIndustry("国家食品药品监督管理总局药品医疗器械", client);
//        if (sss.length > 0) {
//            for (int i = 0; i < sss.length; i++) {
//                System.out.println(sss[i]);
//            }
//        }*/
////    }
//}
